#include "stdafx.h"
#include "TimeManager.h"


#ifndef DEBUG
const u32 TimeManager::cSmudgeFactor = 10;
const u32 TimeManager::cMaxSmudgeFactor = 100;
#else
const u32 TimeManager::cSmudgeFactor = 100;
const u32 TimeManager::cMaxSmudgeFactor = 1000000;
#endif
using namespace std;

TimeManager::TimeManager() : m_paused(true), m_runningClock(0), m_increment(1), m_daysPassed(0)
{
}

TimeManager::~TimeManager()
{
}

void TimeManager::Start()
{
    m_paused = false;
}

void TimeManager::Pause()
{
    m_paused = true;
}

void TimeManager::ToggleStartPause()
{
    m_paused = !m_paused;
}

void TimeManager::IncreaseSpeed()
{
    m_increment += cSmudgeFactor;

    if (m_increment >= cMaxSmudgeFactor)
    {
        m_increment = cMaxSmudgeFactor;
    }
}

void TimeManager::DecreaseSpeed()
{
    m_increment -= cSmudgeFactor;

    if (m_increment <= 1)
    {
        m_increment = 1;
    }
}

void TimeManager::UpdateClock(u32 deltaMS)
{
    //Only update the clock if we are currently not paused
	if (!m_paused)
	{
		f32 dt = deltaMS * m_increment / 1000.0f;
			
		m_runningClock += dt;

		//Number of seconds in a day
		if (m_runningClock > 86400)
		{
			m_runningClock = 0;	
            m_daysPassed++;
		}
	}
}

const string TimeManager::ToString() const
{
    stringstream ss;

    ss << GetHours() << ":" << GetMinutes() << ":" << GetSeconds();

    return ss.str();
}